'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/user/pub/waiting 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			type,
			followList
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		if (type == "getlist") {
			const videolist = await db.collection("a_history").where({
				user_id: userInfo._id
			}).orderBy('_add_time', 'desc').limit(3).get()

			res.videolist = videolist.data

			const followList = await db.collection("a_follow_tv").where({
				user_id: userInfo._id
			}).orderBy('_add_time', 'desc').limit(20).get()

			res.followList = followList.data;
		}

		if (type == "gengxin") {
			for (var i = 0; i < followList.length; i++) {
				const tv_temp = await db.collection('a_tv_series').where({
					tv_id: followList[i].tv_id
				}).orderBy('series', 'desc').limit(1).get()
				if (tv_temp.data.length > 0) {
					followList[i].update_witch = tv_temp.data[0].series
				}
			}
			res.gengxin = followList
		}


		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
